package com.hurl.waguji.biz.download;

import com.hurl.library.spider.UrlPattern;
import com.hurl.library.util.StringUtils;
import com.hurl.waguji.base.Formatter;
import com.hurl.waguji.base.dataprocess.ProcessParams;
import com.hurl.waguji.persistence.DmGpBO;
import com.hurl.waguji.persistence.JcsjGsgkThsBO;

class ProfileGsgkThsProcessor extends BaseDownloadForUpdateProcessor {

	public ProfileGsgkThsProcessor(ProcessParams params,
			DownloadIdentifier identifier) {
		super(params, identifier);
	}

	@Override
	public void convertHTML2BO(String url, String html, BOSaver collector) {


		if(StringUtils.isBlank(html)){
			return;
		}

		JcsjGsgkThsBO bo = new JcsjGsgkThsBO();
		
		String sshy = StringUtils.substringBetween(html, "<td class=\"td\">所属行业：<span>", "</span></td>");
		sshy = Formatter.toString(sshy);
		bo.setSshy(sshy);
		
		String qy = StringUtils.substringBetween(html, "<td class=\"td_2\">区域：<span>", "</span></td>");
		qy = Formatter.toString(qy);
		bo.setQy(qy);
		
		String gswz = StringUtils.substringBetween(html, "<td>公司网址:", "</td>");
		gswz = StringUtils.substringBetween(gswz,"http://","\" target=\"_blank\"");
		if(StringUtils.isNotBlank(gswz)){
			gswz = "http://"+gswz;
		}
		gswz = Formatter.toString(gswz);
		if(gswz!=null){
			gswz = gswz.replace(";", ",");
		}
		bo.setGswz(gswz);
		
		String dsz = StringUtils.substringBetween(html, "<td>董事长：<span>", "</span></td>");
		dsz = StringUtils.substringBetween(dsz,"class=\"a_1\">","</a>");
		dsz = Formatter.toString(dsz);
		bo.setDsz(dsz);
		
		String kggd = StringUtils.substringBetween(html, "<td colspan=\"3\">控股股东：<span>", "</span></td>");
		kggd = StringUtils.substringBetween(kggd,"class=\"a_1\">","</a>");
		kggd = Formatter.toString(kggd);
		bo.setKggd(kggd);
		
		
		String gsjj = StringUtils.substringBetween(html, "<p>公司简介：</p>", "</td>");
		gsjj = StringUtils.substringBetween(gsjj,"<p><span>&nbsp;&nbsp;&nbsp;&nbsp;　　","</span></p>");
		gsjj = Formatter.toString(gsjj);
		bo.setGsjj(gsjj);
		
		String gsmc = StringUtils.substringBetween(html, "公司名称：<span>", "</span></td>");
		gsmc = Formatter.toString(gsmc);
		bo.setGsmc(gsmc);
		
		String ywmc = StringUtils.substringBetween(html, "英文名称：<span>", "</span></td>");
		ywmc = Formatter.toString(ywmc);
		bo.setYwmc(ywmc);

		String zqjc = StringUtils.substringBetween(html, "证券简称：<span>", "</span></td>");
		zqjc = Formatter.toString(zqjc);
		bo.setZqjc(zqjc);

		String cym = StringUtils.substringBetween(html, "曾用名　：<span>", "</span></td>");
		cym = Formatter.toString(cym);
		bo.setCym(cym);

		String zyyw = StringUtils.substringBetween(html, "主营业务：<span>", "</span></td>");
		zyyw = Formatter.toString(zyyw);
		bo.setZyyw(zyyw);

		String frdb = StringUtils.substringBetween(html, "法人代表：<span", "</span></td>");
		frdb = StringUtils.substringBetween(frdb, "class=\"a_1\">", "</a>");
		frdb = Formatter.toString(frdb);
		bo.setFrdb(frdb);

		String zjl = StringUtils.substringBetween(html, "总经理　：<span>", "</span></td>");
		zjl = StringUtils.substringBetween(zjl, "class=\"a_1\">", "</a>");
		zjl = Formatter.toString(zjl);
		bo.setZjl(zjl);

		String dm = StringUtils.substringBetween(html, "<td>董　　秘：<span>", "</span></td>");
		dm = StringUtils.substringBetween(dm, " class=\"a_1\">", "</a>");
		dm = Formatter.toString(dm);
		bo.setDm(dm);

		String dlds = StringUtils.substringBetween(html, "<td>独立董事：<span>", "</span></td>");
		dlds = StringUtils.substringBetween(dlds, "class=\"a_1\">", "</a>");
		dlds = Formatter.toString(dlds);
		bo.setDlds(dlds);

		String lxdh = StringUtils.substringBetween(html, "<td>联系电话：<span>", "</span></td>");
		lxdh = Formatter.toString(lxdh);
		if(lxdh!=null){
			lxdh = lxdh.replace(";", ",");
		}
		bo.setLxdh(lxdh);

		String cz = StringUtils.substringBetween(html, "<td>传　　真：<span>", "</span></td>");
		cz = Formatter.toString(cz);
		if(cz!=null){
			cz = cz.replace(";", ",");
		}
		bo.setCz(cz);

		String dzyx = StringUtils.substringBetween(html, "<td>电子信箱：<span>", "</span></td>");
		dzyx = StringUtils.substringBetween(dzyx, " class=\"a_1\">", "</a>");
		dzyx = Formatter.toString(dzyx);
		if(dzyx!=null){
			dzyx = dzyx.replace(";", ",");
		}
		bo.setDzyx(dzyx);

		String yzbm = StringUtils.substringBetween(html, "<td>邮政编码：<span>", "</span></td>");
		yzbm = Formatter.toString(yzbm);
		bo.setYzbm(yzbm);

		String gsdj = StringUtils.substringBetween(html, "<td>工商登记：<span>", "</span></td>");
		gsdj = Formatter.toString(gsdj);
		bo.setGsdj(gsdj);

		String zcdz = StringUtils.substringBetween(html, "<td colspan=\"2\">注册地址：<span>", "</span></td>");
		zcdz = StringUtils.substringBetween(zcdz, "class=\"a_1\">", "</a>");
		zcdz = Formatter.toString(zcdz);
		bo.setZcdz(zcdz);

		String bgdz = StringUtils.substringBetween(html, "<td colspan=\"2\">办公地址：<span>", "</span></td>");
		bgdz = StringUtils.substringBetween(bgdz, "class=\"a_1\">", "</a>");
		bgdz = Formatter.toString(bgdz);
		bo.setBgdz(bgdz);

		String lsyg = StringUtils.substringBetween(html, "<p>历史沿革：</p>", "</td>");
		lsyg = StringUtils.substringBetween(lsyg, "<p><span>&nbsp;&nbsp;&nbsp;&nbsp;　　", "</span></p>");
		lsyg = Formatter.toString(lsyg);
		bo.setLsyg(lsyg);
		
		String clrq = StringUtils.substringBetween(html, "成立日期　：<span>", "</span></td>");
		clrq = Formatter.toString(clrq);
		bo.setClrq(clrq);
		
		String ssrq = StringUtils.substringBetween(html, "上市日期　：<span>", "</span></td>");
		ssrq = Formatter.toString(ssrq);
		bo.setSsrq(ssrq);
		
		String fxjg = StringUtils.substringBetween(html, "发行价格　：<span>", "</span></td>");
		fxjg = StringUtils.substringBetween(fxjg,null, "元");
		Double fxjgD = Formatter.toDouble(fxjg);
		bo.setFxjg(fxjgD);
		
		String fxsl = StringUtils.substringBetween(html, "发行数量　：<span>", "</span></td>");
		fxsl = StringUtils.substringBetween(fxsl,null, "万股");
		Double fxslD = Formatter.toDouble(fxsl);
		if(fxslD!=null){
			fxslD = fxslD*10000;
		}
		bo.setFxsl(fxslD);
		
		String srkpj = StringUtils.substringBetween(html, "<td>首日开盘价：<span>", "</span></td>");
		srkpj = StringUtils.substringBetween(srkpj,null, "元");
		Double srkpjD = Formatter.toDouble(srkpj);
		bo.setSrkpj(srkpjD);
		
		String yjmz = StringUtils.substringBetween(html, "预计募资　：<span>", "</span></td>");
		yjmz = StringUtils.substringBetween(yjmz,null, "万元");
		Double yjmzD = Formatter.toDouble(yjmz);
		if(yjmzD!=null){
			yjmzD = yjmzD*10000;
		}
		bo.setYjmz(yjmzD);
		
		String sjmz = StringUtils.substringBetween(html, "<td>实际募资　：<span>", "</span></td>");
		sjmz = StringUtils.substringBetween(sjmz,null, "万元");
		Double sjmzD = Formatter.toDouble(sjmz);
		if(sjmzD!=null){
			sjmzD = sjmzD*10000;
		}
		bo.setSjmz(sjmzD);
		
		String fxsyl = StringUtils.substringBetween(html, "<td>发行市盈率：<span>", "</span></td>");
		fxsyl = StringUtils.substringBetween(fxsyl,null, "倍");
		Double fxsylD = Formatter.toDouble(fxsyl);
		bo.setFxsyl(fxsylD);
		
		String fxzql = StringUtils.substringBetween(html, "<td>发行中签率：<span>", "</span></td>");
		fxzql = StringUtils.substringBetween(fxzql,null, "%");
		Double fxzqlD = Formatter.toDouble(fxzql);
		if(fxzqlD!=null){
			fxzqlD=fxzqlD/100;
		}
		bo.setFxzql(fxzqlD);
		
		String zcxs = StringUtils.substringBetween(html, "主承销商　：<span>", "</span></td>");
		zcxs = Formatter.toString(zcxs);
		bo.setZcxs(zcxs);
		
		String ssbjr = StringUtils.substringBetween(html, "上市保荐人：<span>", "</span></td>");
		ssbjr = Formatter.toString(ssbjr);
		if(ssbjr!=null){
			ssbjr = ssbjr.replace(";", ",");
		}
		bo.setSsbjr(ssbjr);
		bo.setGpDm(context.getEnvAsString("gpdm"));
		bo.setLastupdate(currentTime);
		
		collector.addBO(bo);
	}

	@Override
	public UrlPattern getUrlPattern() {
		return new StockIteratorUrlPattern(context) {
			
			@Override
			public String bo2url(DmGpBO bo) {
				return "http://basic.10jqka.com.cn/"+bo.getGpDmJ()+"/gsgk.html";
			}
		};
	}
}
